package com.apes.fn.scm.retailOrder.service.tc.commission;

import com.apes.framework.util.MapUtil;
import com.apestech.framework.json.JSON;
import com.apestech.framework.json.JSONObject;
import com.apestech.framework.util.StringFuncUtil;
import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: TCExpressUtil
 * @Description: 提成公式计算
 * @author: ZhengZeXian
 * @create: 2021/8/23 11:40
 */
public class TCExpressUtil extends StringFuncUtil {

    /**
     * 总执行方法
     * @param express 表达式
     * @param value 参数值
     * private boolean isPrecise; 是否需要高精度计算
     * @throws Exception
     */
    public static Object execute(String express, Map<String, Object> value) throws Exception{
        ExpressRunner runner = new ExpressRunner(true,false);
        DefaultContext<String, Object> context = new DefaultContext<String, Object>();
        context.putAll(value);
        return runner.execute(express, context, null, true, false);
    }

    public static void main(String[] args) throws Exception{
        //测试脚本
        String s = "{\"PROFIT_AMT\":0.00,\"SALE_QTY\":1,\"NKDK_AMT\":0,\"DK_QTY\":0,\"MAIN_SALESMAN\":\"0001822\",\"TJRQ\":\"2021-08-28 00:00:00\",\"conditionId\":\"KHCBJ\",\"YXSDJ\":273,\"ID\":3194110,\"PROFIT_AMT_RETURN\":null,\"DEPT_ID\":\"6084R001\",\"YYHDJ\":273,\"SOURCE_BUSINESS_TYPE\":null,\"SALE_AMT\":130,\"condition\":[{\"field\":\"START_DATE\",\"value\":\"2021-08-29 13:39:36\",\"operator\":\"LTE\"},{\"field\":\"END_DATE\",\"value\":\"2021-08-29 13:39:36\",\"operator\":\"GTE\"}],\"DSBJ\":0,\"SOURCE\":\"FW60842108529127\",\"T024\":0,\"T022\":0.1,\"T023\":0,\"T021\":0.9,\"SYS_RQ\":\"2021-08-29 13:39:36\",\"RETAIL_ORDER_ID\":\"LS60842108525103\",\"sys_break\":\"1\",\"T401\":1,\"autoCompletion\":null,\"SERVE_TYPE_ID\":\"004\",\"PLATE_LICENSE\":\"粤YL6186\",\"FXDK_AMT\":0,\"BRAND_ID\":\"003348\",\"REFER_TAX\":0,\"PRODUCT_UOM_ID\":1117732,\"T013\":0,\"T014\":0,\"T011\":0.05,\"T012\":0.03,\"COMPANY_ID\":\"6084\",\"TCBL_JE\":0,\"ORDER_TYPE\":\"server\",\"PRODUCT_ID\":\"0000000332\",\"HBDK_AMT\":0,\"LOCK_PRICE\":95,\"ASSESSMENT_COST_PRICE\":0,\"CLASSIFY_ID\":\"S01040302001\",\"OPERATION\":\"赋能店\",\"T002\":0,\"DISCOUNT_AMOUNT\":0,\"SUB_SALESMAN\":null,\"T001\":0,\"RETAIL_ITEM_ID\":\"1093743\"}\n";
        JSONObject jsonObject = JSON.toJSON(s);

        Object execute = execute(TCFormula.XSTC_TCBL_JE, new HashMap(jsonObject));
    }
}
